<?php
/**
 * Created by PhpStorm.
 * User: 韩梦雅
 * Date: 2019/2/22
 * Time: 13:39
 */
namespace App\Http\Controllers\Admin\Invite;
use App\Http\Controllers\BaseApiController;
use App\Services\Admin\Invite\IndexService;
use Validator;
use Illuminate\Http\Request;

class IndexController extends BaseApiController
{
    private $service;
    public function __construct(IndexService $service)
    {
        //继承基类的构造方法
        parent::__construct();
        //依赖注入service
        $this->service=$service;
    }
    //查询招聘首页数据
    public function List()
    {
        $arr = $this->service->companyList();
        $res = $this->service->industryList();
        return json_encode(['arr'=>$arr,'res'=>$res,'code'=>'200']);
    }
    //校外招聘搜索
    public function Search(Request $request)
    {
        if ($request->isMethod('get'))
        {
            $sou = $request->all();
            $a = $this->service->checkSou($sou);
            if($a)
            {
                $arr = $this->service->inviteSearch($sou);
                return $arr;
            }
            else{
                return response()->json(['status'=>'0']);
            }
        }
    }
    //职位列表查询
    public function positionList(Request $request)
    {
        $a = $this->service->checkSou($request->all());
        if(!$a)
        {
            $page = 1;
        }
        else{
            $res = $request->all();
            $page = $res['sou']+1;
        }
        $arr = $this->service->positionList($page);
        return $arr;
    }
    //详情查询
    public function positionInfo(Request $request)
    {
        //接值
        if($request->isMethod('post'))
        {
            //验证是否合法
            $a = $this->service->checkSou($request->all());
            if($a)
            {
                $aa=$request->all();
                //调用service层
                $arr = $this->service->positionInfo($aa);
                return $arr;
            }
            else{
                return response()->json(['status'=>'0']);
            }
        }
        else{
            return response()->json(['status'=>'0']);
        }
    }
}